<?php
 /**
 *  +---------------------------------------------------------------------- 
 *  | 文件功能：用户模型
 *  +---------------------------------------------------------------------- 
 *  | Copyright (c) 2022~2024 https://www.huihuiv.com All rights reserved.
 *  +---------------------------------------------------------------------- 
 *  | Create At: 2024年02月26日 18:12:12
 *  +---------------------------------------------------------------------- 
 *  | Author: 半壶水 <star@cqshanwen.com>
 *  +---------------------------------------------------------------------- 
 */

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use HasApiTokens, HasFactory, Notifiable;

    // 用户表表名称
    protected $table = 'sw_user';

    // 用户表主键
    protected $primaryKey = 'uid';

    // 自动写入时间戳
    public $timestamps = true;

    // 写入时间戳样式
    protected $dateFormat = 'U';

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'phone',
        'username',
        'password',
        'gid'
    ];

    /**
     * 默认自动完成字段
     *
     * @var array
     */
    protected $attributes = [
        'gid' => 1
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];


    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

    // 关联用户组表
    public function group()
    {
        return $this->hasMany(GroupModel::class, 'gid', 'gid');
    }

    // 反向关联主题基础信息表
    public function content_simple()
    {
        return $this->belongsTo(ContentSimpleModel::class, 'author', 'uid');
    }
}
